package com.yic.module.mes.dal.mysql.processrouteinfo;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.mes.dal.dataobject.processRoute.ProcessRouteDO;
import com.yic.module.mes.dal.dataobject.processrouteinfo.ProcessRouteInfoDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.mes.controller.admin.processrouteinfo.vo.*;

/**
 * 工艺路线详细配置 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ProcessRouteInfoMapper extends BaseMapperX<ProcessRouteInfoDO> {

    default PageResult<ProcessRouteInfoDO> selectPage(ProcessRouteInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eqIfPresent(ProcessRouteInfoDO::getRouteId, reqVO.getRouteId())
                .eqIfPresent(ProcessRouteInfoDO::getProcessId, reqVO.getProcessId())
                .eqIfPresent(ProcessRouteInfoDO::getNextProcessId, reqVO.getNextProcessId())
                .eqIfPresent(ProcessRouteInfoDO::getSubsequence, reqVO.getSubsequence())
                .eqIfPresent(ProcessRouteInfoDO::getLink, reqVO.getLink())
                .eqIfPresent(ProcessRouteInfoDO::getMainProcess, reqVO.getMainProcess())
                .eqIfPresent(ProcessRouteInfoDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(ProcessRouteInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProcessRouteInfoDO::getId));
    }

    default List<ProcessRouteInfoDO> selectList(ProcessRouteInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eqIfPresent(ProcessRouteInfoDO::getRouteId, reqVO.getRouteId())
                .eqIfPresent(ProcessRouteInfoDO::getProcessId, reqVO.getProcessId())
                .eqIfPresent(ProcessRouteInfoDO::getNextProcessId, reqVO.getNextProcessId())
                .eqIfPresent(ProcessRouteInfoDO::getSubsequence, reqVO.getSubsequence())
                .eqIfPresent(ProcessRouteInfoDO::getLink, reqVO.getLink())
                .eqIfPresent(ProcessRouteInfoDO::getMainProcess, reqVO.getMainProcess())
                .eqIfPresent(ProcessRouteInfoDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(ProcessRouteInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProcessRouteInfoDO::getId));
    }

    default int deleteByRouteId(Long routeId) {
        return delete(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eq(ProcessRouteInfoDO::getRouteId, routeId));
    }

    default List<ProcessRouteInfoDO> selectList(Long id) {
        return selectList(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eq(ProcessRouteInfoDO::getRouteId, id));
    }

    default List<ProcessRouteInfoDO> selectListByRouteId(Collection<Long> routeIds) {
        return selectList(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .inIfPresent(ProcessRouteInfoDO::getRouteId, routeIds));
    }

    default List<ProcessRouteInfoDO> selectListByRouteId(Long routeId) {
        return selectList(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eq(ProcessRouteInfoDO::getRouteId, routeId));
    }

    default ProcessRouteInfoDO selectOneByProcessId(Long processId) {
        return selectOne(new LambdaQueryWrapperX<ProcessRouteInfoDO>()
                .eq(ProcessRouteInfoDO::getProcessId, processId)
                .last("limit 1"));
    }
}
